import CryptoJS from 'crypto-js'

function encrypt(word, keyStr){
    keyStr = keyStr ? keyStr : "Welcome TPF Arch";
    var key  = CryptoJS.enc.Latin1.parse(keyStr);
    var srcs = CryptoJS.enc.Utf8.parse(word);
    var encrypted = CryptoJS.AES.encrypt(srcs, key, {iv:key, mode:CryptoJS.mode.CBC,padding: CryptoJS.pad.ZeroPadding});
    return encrypted.toString();
}

function decrypt(word,keyStr){
  keyStr = keyStr ? keyStr : "Welcome TPF Arch";
  var key  = CryptoJS.enc.Latin1.parse(keyStr);
  var decrypted = CryptoJS.AES.decrypt(word, key, {iv:key, mode:CryptoJS.mode.CBC,padding: CryptoJS.pad.ZeroPadding});
  return CryptoJS.enc.Utf8.stringify(decrypted).toString();
}

export default {
    encode: encrypt,
    decode: decrypt
};
